package com.baby.growth.controller;

import com.baby.growth.module.BabyOutput;
import com.baby.growth.service.BabyOutputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BabyOutputController {
    @Autowired
    BabyOutputService babyOutputService;

    @GetMapping("/api/babyoutputdatas")
    public List<BabyOutput> list() throws Exception {
        return babyOutputService.list();
    }

    @GetMapping("/api/babytodayoutputdatas")
    public List<BabyOutput> listToday() throws Exception {
        return babyOutputService.lisToday();
    }

    @PostMapping("/api/babyoutputdata")
    public BabyOutput addOrUpdate(@RequestBody BabyOutput babyOutput) throws Exception {
        babyOutputService.addOrUpdate(babyOutput);
        return babyOutput;
    }

    @PostMapping("/api/babyoutputdata/delete")
    public void deleted(@RequestBody BabyOutput babyOutput) throws Exception {
        babyOutputService.deleteById(babyOutput.getId());
    }
}
